package sysytmRepo

import (
	"gorm.io/gorm"
	"ruoyi/domain/entity/response"
	"ruoyi/domain/entity/system"
	"ruoyi/domain/repository"
)

type SysRoleDeptRepo struct {
	db *gorm.DB
}

func SysRoleDeptRepository(db *gorm.DB) *SysRoleDeptRepo {
	return &SysRoleDeptRepo{db}
}

var _ repository.SysRoleDeptRepository = &SysRoleDeptRepo{}

func (r *SysRoleDeptRepo) DeleteRoleDept(roleIds string) {
	sql := "delete from sys_role_dept where role_id in ( " + roleIds + " )"
	err := r.db.Exec(sql).Error
	if err != nil {
		panic(response.ReturnFailMsg(err.Error()))
	}
}

func (r *SysRoleDeptRepo) DeleteRoleDeptByRole(roleId string) {
	err := r.db.Where("role_id = ?", roleId).Delete(&system.SysRoleDept{}).Error
	if err != nil {
		panic(response.ReturnFailMsg(err.Error()))
	}

}
